package yshttp

import (
	"github.com/gogf/gf/v2/net/ghttp"
	"time"
)

// MiddlewareTimeMs ms 级时间测量
func MiddlewareTimeMs(r *ghttp.Request) {
	start := time.Now()
	r.Middleware.Next()
	result := time.Since(start)
	log().Infof(r.GetCtx(), "执行时间: %d ms", result.Milliseconds())
}

// MiddlewareTimeS 秒级时间测量
func MiddlewareTimeS(r *ghttp.Request) {
	start := time.Now()
	r.Middleware.Next()
	result := time.Since(start)
	log().Infof(r.GetCtx(), "执行时间: %d ms", result.Milliseconds())
}

func MiddlewareLogReqAndRes(r *ghttp.Request) {
	log().Debug(r.GetCtx(), r.GetMap())
	r.Middleware.Next()
	log().Debug(r.GetCtx(), r.Response.BufferString())
}
